home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / PROGS / GLC / GLCDEMO.C next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  2.3 KB  |  112 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1996. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <string.h>
  9. #include <GL/glut.h>
  10. #include <GL/glc.h>
  11.  
  12. int font = 1;
  13. char defaultMessage[] = "GLUT means OpenGL.";
  14. char *message = defaultMessage;
  15.  
  16. int angle = 0;
  17.  
  18. void
  19. selectFont(int newfont)
  20. {
  21.   font = newfont;
  22.   glutPostRedisplay();
  23. }
  24.  
  25. void
  26. selectMessage(int msg)
  27. {
  28.   switch (msg) {
  29.   case 1:
  30.     message = "abcdefghijklmnop";
  31.     break;
  32.   case 2:
  33.     message = "ABCDEFGHIJKLMNOP";
  34.     break;
  35.   }
  36. }
  37.  
  38. void
  39. tick(void)
  40. {
  41.   angle -= 2;
  42.   glutPostRedisplay();
  43. }
  44.  
  45. void
  46. display(void)
  47. {
  48. #if 0
  49.   int len, i;
  50.  
  51.   glClear(GL_COLOR_BUFFER_BIT);
  52.   glPushMatrix();
  53.   glRotatef(angle, 0.0, 0.0, 1.0);
  54.   glTranslatef(-750, 0, 0);
  55.   len = (int) strlen(message);
  56.   for (i = 0; i < len; i++) {
  57.     glutStrokeCharacter(font, message[i]);
  58.   }
  59.   glPopMatrix();
  60. #else
  61.   glPushMatrix();
  62.   glClear(GL_COLOR_BUFFER_BIT);
  63.   glcRotate(angle);
  64.   glRasterPos2f(100, 100);
  65.   glcFont(font);
  66.   glcRenderString(message);
  67.   glPopMatrix();
  68. #endif
  69.   glutSwapBuffers();
  70. }
  71.  
  72. int
  73. main(int argc, char **argv)
  74. {
  75.   int submenu;
  76.  
  77.   glutInit(&argc, argv);
  78.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  79.   glutInitWindowSize(600, 600);
  80.   glutCreateWindow("GLC font library demo");
  81.   glMatrixMode(GL_PROJECTION);
  82.   glLoadIdentity();
  83.   gluOrtho2D(0, 2000, 0, 2000);
  84.   glMatrixMode(GL_MODELVIEW);
  85.   glEnable(GL_LINE_SMOOTH);
  86.   glEnable(GL_BLEND);
  87.   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  88.   glLineWidth(3.0);
  89.   glTranslatef(1000, 1000, 0);
  90.   glClearColor(0.0, 0.0, 0.0, 1.0);
  91.   glColor3f(1.0, 1.0, 1.0);
  92.   glutDisplayFunc(display);
  93.   glutIdleFunc(tick);
  94.   submenu = glutCreateMenu(selectMessage);
  95.   glutAddMenuEntry("abc", 1);
  96.   glutAddMenuEntry("ABC", 2);
  97.   glutCreateMenu(selectFont);
  98.   glutAddMenuEntry("Helvetica", 1);
  99.   glutAddMenuEntry("Courier", 2);
  100.   glutAddMenuEntry("Times", 3);
  101.   glutAddSubMenu("Messages", submenu);
  102.   glutAttachMenu(GLUT_RIGHT_BUTTON);
  103.   glcContext(glcGenContext());
  104.   glcScale(30, 30);
  105.   glcNewFontFromFamily(1, "Helvetica");
  106.   glcNewFontFromFamily(2, "Courier");
  107.   glcNewFontFromFamily(3, "Times");
  108.   glcFont(font);
  109.   glutMainLoop();
  110.   return 0;             /* ANSI C requires main to return int. */
  111. }
  112.